home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / pdox693.zip / TI1112.ASC < prev    next >
Text File  |  1992-08-25  |  16KB  |  661 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Paradox                               NUMBER  :  1112
  8.   VERSION  :  4.0
  9.        OS  :  DOS
  10.      DATE  :  August 25, 1992                         PAGE  :  1/10
  11.  
  12.     TITLE  :  Various Examples Using the IIF (Immediate If)
  13.               Function in Reports and Forms.
  14.  
  15.  
  16.  
  17.  
  18.   This Technical Information sheet provides examples of using the
  19.   PAL Immediate If function, IIF(), in calculated fields of forms
  20.   or reports.  Although the examples do not cover all possible
  21.   uses, they will provide you with techniques which you could apply
  22.   to your own applications.
  23.  
  24.   NOTE: You should know how to use PAL functions in reports and
  25.   forms to understand all the material contained in this Technical
  26.   Information sheet.  You should also read the information in the
  27.   sections of the following chapters from the Paradox manuals:
  28.  
  29.        PAL Reference, "IIF()" in PAL Commands and Functions
  30.        PAL Programmers Guide, "IIF()" in Chapter 4
  31.        Paradox User's Guide, PAL Functions in Reports, in Chapter 8
  32.  
  33.   Any other PAL functions referenced in this document are detailed
  34.   in the PAL Reference manual.
  35.  
  36.   The syntax for the IIF() function is:
  37.  
  38.        IIF(Condition, ValueIfTrue, ValueIfFalse)
  39.  
  40.   where Condition is any expression that evaluates to a logical
  41.   value of True or False; ValueIfTrue is the value returned if
  42.   Condition evaluates to True; and ValueIfFalse is the value
  43.   returned if Condition evaluates to False.
  44.  
  45.   The first eight examples take you through a credit card payment
  46.   scenario using IIF() functions.  The sample Credit database has
  47.   the following structure and records:
  48.  
  49.   Credit │ Name │ Balance  │  Limit   │ Due Date │ Gender
  50.   ───────┼──────┼──────────┼──────────┼──────────┼───────
  51.          │ Bob  │ 1,100.00 │ 1,100.00 │ 12/02/91 │  M
  52.          │ Judy │   250.00 │ 3,000.00 │ 10/20/91 │  F
  53.          │ Mark │    12.00 │ 2,000.00 │ 6/12/92  │  m
  54.          │ Pam  │     0.00 │ 2,500.00 │          │  f
  55.  
  56.   NOTE: The Balance and Limit fields have a field type of $.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.   PRODUCT  :  Paradox                               NUMBER  :  1112
  74.   VERSION  :  4.0
  75.        OS  :  DOS
  76.      DATE  :  August 25, 1992                         PAGE  :  2/10
  77.  
  78.     TITLE  :  Various Examples Using the IIF (Immediate If)
  79.               Function in Reports and Forms.
  80.  
  81.  
  82.  
  83.  
  84.   Example 1:
  85.  
  86.   Suppose you wanted to show on a report or form the payment due
  87.   date, but wanted to show the month value with leading zeros when
  88.   the month is a single digit.  You could do so by placing the
  89.   following calculated field:
  90.  
  91.   IIF(LEN([Due Date])=7, "0"+STRVAL([Due Date]), [Due Date])
  92.  
  93.   The LEN() function returns the length of an expression.  Its
  94.   syntax is LEN(Expression).  The STRVAL() function converts any
  95.   expression to a string.  Its syntax is STRVAL(Expression).
  96.  
  97.   NOTE: When you place a calculated field that includes PAL
  98.   functions, the field mask that appears is alphanumeric (as A's in
  99.   the report).  It is necessary to use the arrow keys to adjust the
  100.   number of characters that the calculated field should display.
  101.   In Example 1, adjust the calculated field to display 8 characters
  102.   for date (i.e. MM/DD/YY).  Do not be concerned!  This is simply
  103.   the way that Paradox displays these types of calculated fields.
  104.  
  105.   Explanation:
  106.  
  107.   If the length of the Due Date value is 7, the due date has a
  108.   single digit month (for example, Mark's due date--2 characters
  109.   each for the day and year, 1 character for the month, and 1
  110.   character for each slash).  Thus, if you add a zero to the string
  111.   value of the date the month value is now 2 characters.  If the
  112.   length of Due Date is already 8, then the month is a two digit
  113.   number and the leading zero is not necessary.
  114.  
  115.   Result:
  116.  
  117.        Name      IIF() Result
  118.        ───────   ────────────
  119.        Bob       12/02/91
  120.        Judy      10/20/91
  121.        Mark      06/12/92
  122.        Pam
  123.  
  124.   Notice how Mark's due date now has 06 for the month.
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.   PRODUCT  :  Paradox                               NUMBER  :  1112
  140.   VERSION  :  4.0
  141.        OS  :  DOS
  142.      DATE  :  August 25, 1992                         PAGE  :  3/10
  143.  
  144.     TITLE  :  Various Examples Using the IIF (Immediate If)
  145.               Function in Reports and Forms.
  146.  
  147.  
  148.  
  149.  
  150.   Example 2:
  151.  
  152.   If a person has not yet reached their credit limit, indicate that
  153.   they still have credit available, otherwise indicate that no
  154.   credit remains:
  155.  
  156.   IIF([Balance]<[Limit], "Credit Available", "No Credit Available")
  157.  
  158.   Explanation:
  159.  
  160.   If the Balance is less than Limit, return "Credit Available",
  161.   otherwise return "No Credit Available".
  162.  
  163.   Result:
  164.  
  165.        Name      IIF() Result
  166.        ───────   ───────────────────
  167.        Bob       No Credit Available
  168.        Judy      Credit Available
  169.        Mark      Credit Available
  170.        Pam       Credit Available
  171.  
  172.   Notice that Bob is the only person who has used up his full
  173.   credit limit (Balance = 1100.00, Limit = 1100.00).
  174.  
  175.  
  176.   Example 3:
  177.  
  178.   If there is a credit card balance, show a minimum payment due (2%
  179.   of the balance).  Otherwise, show zero since there is no
  180.   balance due:
  181.  
  182.   IIF([Balance]>0, [Balance]*.02, 0)
  183.  
  184.   Explanation:
  185.  
  186.   If the Balance is greater than zero, return 2% of the Balance
  187.   value, otherwise return zero.
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.   PRODUCT  :  Paradox                               NUMBER  :  1112
  206.   VERSION  :  4.0
  207.        OS  :  DOS
  208.      DATE  :  August 25, 1992                         PAGE  :  4/10
  209.  
  210.     TITLE  :  Various Examples Using the IIF (Immediate If)
  211.               Function in Reports and Forms.
  212.  
  213.  
  214.  
  215.  
  216.   Result:
  217.  
  218.        Name      IIF() Result
  219.        ──────    ────────────
  220.        Bob       22.00
  221.        Judy      5.00
  222.        Mark      .24
  223.        Pam       0
  224.  
  225.  
  226.   Example 4:
  227.  
  228.   Paying 2% on any balance means that Mark would pay $0.24 and Judy
  229.   would pay $5.00.  In order to assure that a minimum payment of
  230.   $20 is received, the previous IIF() expression could be modified
  231.   like this:
  232.  
  233.   IIF([Balance]*.02<20, 20, [Balance]*.02)
  234.  
  235.   Explanation:
  236.  
  237.   If 2% of the balance is less than $20, require a payment of $20.
  238.   Otherwise, since the balance is high enough such that a 2%
  239.   payment is $20 or greater, require a 2% payment.
  240.  
  241.   Result:
  242.  
  243.        Name      IIF() Result
  244.        ───────   ────────────
  245.        Bob       22.00
  246.        Judy      20
  247.        Mark      20
  248.        Pam       20
  249.  
  250.   Judy and Mark now pay a minimum of $20.
  251.  
  252.   NOTE: To format the output so that it looks like currency values,
  253.   refer to Example 6 in this Technical Information sheet.
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.   PRODUCT  :  Paradox                               NUMBER  :  1112
  272.   VERSION  :  4.0
  273.        OS  :  DOS
  274.      DATE  :  August 25, 1992                         PAGE  :  5/10
  275.  
  276.     TITLE  :  Various Examples Using the IIF (Immediate If)
  277.               Function in Reports and Forms.
  278.  
  279.  
  280.  
  281.  
  282.   Example 5:
  283.  
  284.   But what about Mark?  He has a balance of $12.00.  The $20
  285.   minimum payment means he is expected to pay more than he owes.
  286.   And Pam has a zero balance--she does not owe anything!  The
  287.   previous IIF() expression could be further modified so that
  288.   anyone with a balance less than $20 pays it in full:
  289.  
  290.   IIF([Balance]<20, [Balance], IIF([Balance]*.02<20, 20,
  291.   [Balance]*.02))
  292.  
  293.   (The above expression must be entered on one line).
  294.  
  295.   Note: Notice how you can nest IIF() statements.
  296.  
  297.   Explanation:
  298.  
  299.   This nested IIF() expression states that if the balance is less
  300.   than $20, the full balance is due.  Otherwise, the balance is $20
  301.   or greater.  So, if the balance is $20 or greater and 2% of this
  302.   balance is less than $20, $20 is due.  Otherwise, require a 2%
  303.   payment of the balance (since this 2% payment will be at least
  304.   $20).
  305.  
  306.   Result:
  307.  
  308.        Name      IIF() Result
  309.        ───────   ────────────
  310.        Bob       22.00
  311.        Judy      20
  312.        Mark      12.00
  313.        Pam       0
  314.  
  315.   Now, Mark and Pam only pay what they owe.
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.   PRODUCT  :  Paradox                               NUMBER  :  1112
  338.   VERSION  :  4.0
  339.        OS  :  DOS
  340.      DATE  :  August 25, 1992                         PAGE  :  6/10
  341.  
  342.     TITLE  :  Various Examples Using the IIF (Immediate If)
  343.               Function in Reports and Forms.
  344.  
  345.  
  346.  
  347.  
  348.   Example 6:
  349.  
  350.   Finally, to format the output so that it looks like currency,
  351.   embed the IIF() statement within a FORMAT() statement.
  352.  
  353.   FORMAT("W10.2, E$",
  354.   IIF([Balance]<20, [Balance], IIF([Balance]*.02<20, 20,
  355.   [Balance]*.02)))
  356.  
  357.   (The above expression must be entered on one line.)
  358.  
  359.   The FORMAT() function allows you to format a string.  Its syntax
  360.   is FORMAT(FormatSpec, String).
  361.  
  362.   Explanation:
  363.  
  364.   Take the resulting value of the IIF() statement and format it as
  365.   10 digits with 2 decimal places, and use a floating dollar sign.
  366.  
  367.   Result:
  368.  
  369.        Name      IIF() Result
  370.        ───────   ────────────
  371.        Bob           $22.00
  372.        Judy          $20.00
  373.        Mark          $12.00
  374.        Pam            $0.00
  375.  
  376.  
  377.   Example 7:
  378.  
  379.   Suppose you wanted to display the full gender of a cardholder
  380.   based on the Gender field (which contains "M" for male and "F"
  381.   for female).  In order to display "Male" or "Female" in a report
  382.   or form, you could use the following:
  383.  
  384.   IIF([Gender]="M", "Male", "Female")
  385.  
  386.   Explanation:
  387.  
  388.   If Gender is "M", return "Male", otherwise return "Female."
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.   PRODUCT  :  Paradox                               NUMBER  :  1112
  404.   VERSION  :  4.0
  405.        OS  :  DOS
  406.      DATE  :  August 25, 1992                         PAGE  :  7/10
  407.  
  408.     TITLE  :  Various Examples Using the IIF (Immediate If)
  409.               Function in Reports and Forms.
  410.  
  411.  
  412.  
  413.  
  414.   Result:
  415.  
  416.        Name      Gender    IIF() Result
  417.        ──────    ───────   ────────────
  418.        Bob       M         Male
  419.        Judy      F         Female
  420.        Mark      m         Female         <-----
  421.        Pam       f         Female
  422.  
  423.  
  424.   Example 8:
  425.  
  426.   Notice that Mark's gender displayed as Female even though an "m"
  427.   was entered.  Since string comparisons are case-sensitive, "m" is
  428.   not equivalent to "M" and, therefore, returns "Female".  To
  429.   assure a proper comparison when Gender values are lower case,
  430.   use:
  431.  
  432.   IIF(UPPER([Gender])="M", "Male", "Female")
  433.  
  434.   The UPPER() function allows you to change a string to upper-case.
  435.   Its syntax is UPPER(Expression).
  436.  
  437.   Explanation:
  438.  
  439.   Convert the Gender value to upper-case.  Then, if it equals "M",
  440.   return "Male", otherwise return "Female".
  441.  
  442.   Result:
  443.  
  444.        Gender    IIF() Result
  445.        ───────   ────────────
  446.        M         Male
  447.        F         Female
  448.        m         Male
  449.        f         Female
  450.  
  451.   Since the UPPER() function converts "m" to "M", "Male" is
  452.   returned for both "M" and "m."
  453.  
  454.   ┌──────────────────────────────────────────────────────────────┐
  455.   │The next set of examples no longer deal with the Credit table │
  456.   └──────────────────────────────────────────────────────────────┘
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.   PRODUCT  :  Paradox                               NUMBER  :  1112
  470.   VERSION  :  4.0
  471.        OS  :  DOS
  472.      DATE  :  August 25, 1992                         PAGE  :  8/10
  473.  
  474.     TITLE  :  Various Examples Using the IIF (Immediate If)
  475.               Function in Reports and Forms.
  476.  
  477.  
  478.  
  479.  
  480.   Example 9:
  481.  
  482.   Suppose you had the following movie review table:
  483.  
  484.   Reviews   │    Movie     │    Critic 1  │    Critic 2
  485.   ──────────┼──────────────┼──────────────┼──────────────
  486.             │    Car Wash  │    2         │
  487.             │    Fame      │              │    1
  488.             │    Splash    │    3         │
  489.             │    Top Gun   │              │    5
  490.  
  491.   The movie review table contains reviews from two critics.  Only
  492.   one of the two critics reviews any single movie, never both.  In
  493.   order to represent the score with asterisks (using one asterisk
  494.   per point), we could use the following expression:
  495.  
  496.   FILL("*", IIF(ISBLANK([Critic 1]), [Critic 2], [Critic 1]))
  497.  
  498.   The FILL() function allows you to repeat a character.  Its syntax
  499.   is FILL(Expression, Number).  The ISBLANK() function tests
  500.   whether an expression is blank or not.  Its syntax is
  501.   ISBLANK(Expression).
  502.  
  503.   Explanation:
  504.  
  505.   The IIF() function is used to return a value which will inform
  506.   the FILL() function how many asterisks to display.  If the Critic
  507.   1 field is blank, we know critic 2 reviewed the movie--return the
  508.   value of the Critic 2 field.  If the Critic 1 field is non-blank,
  509.   we know critic 1 reviewed the movie--return the value of the
  510.   Critic 1 field.
  511.  
  512.   Result:
  513.  
  514.        Movie     LEN()/IIF() Result
  515.        ───────   ──────────────────
  516.        Car Wash  **
  517.        Fame      *
  518.        Splash    ***
  519.        Top Gun   *****
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.   PRODUCT  :  Paradox                               NUMBER  :  1112
  536.   VERSION  :  4.0
  537.        OS  :  DOS
  538.      DATE  :  August 25, 1992                         PAGE  :  9/10
  539.  
  540.     TITLE  :  Various Examples Using the IIF (Immediate If)
  541.               Function in Reports and Forms.
  542.  
  543.  
  544.  
  545.  
  546.   Example 10:
  547.  
  548.   Suppose you had an employee table which had a DOB field for Date
  549.   Of Birth.  You could use the following expression to see if today
  550.   was their birthday:
  551.  
  552.   IIF(MONTH([DOB])=MONTH(TODAY()) AND DAY([DOB])=DAY(TODAY()),
  553.   "Happy Birthday!", "")
  554.  
  555.   (The above expression must be entered on one line.)
  556.  
  557.   The MONTH() function returns the numeric month value of a date.
  558.   Its syntax is MONTH(Date).  The DAY() function returns the
  559.   numeric day value of a date.  Its syntax is DAY(Date).
  560.  
  561.   Explanation:
  562.  
  563.   If the month value of the employee's date of birth is the same as
  564.   the current month and the day value of the employee's date of
  565.   birth is the same as the current day, then it is the employee's
  566.   birthday--display message.  Otherwise, it is not the employee's
  567.   birthday--do not display anything.  Note: Notice how you can use
  568.   the "AND" operator to make a compound condition.
  569.  
  570.   Result:
  571.  
  572.   Assume today is 7/04/90.
  573.  
  574.        Employee ID  DOB       IIF() Result
  575.        ───────────  ────────  ───────────────
  576.             1       7/04/62   Happy Birthday!
  577.             2       12/25/43
  578.             3       7/04/57   Happy Birthday!
  579.             4       1/01/70
  580.  
  581.  
  582.   To order other Technical Information sheets by fax, phone our
  583.   TechFax number at (800)822-4269.  A menu system will guide you
  584.   through ordering Technical Information sheets which will be faxed
  585.   directly to you.  You can even order a catalog which lists
  586.   articles you can request when calling the TechFax Number.
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.   PRODUCT  :  Paradox                               NUMBER  :  1112
  602.   VERSION  :  4.0
  603.        OS  :  DOS
  604.      DATE  :  August 25, 1992                        PAGE  :  10/10
  605.  
  606.     TITLE  :  Various Examples Using the IIF (Immediate If)
  607.               Function in Reports and Forms.
  608.  
  609.  
  610.  
  611.  
  612.   DISCLAIMER: You have the right to use this technical information
  613.   subject to the terms of the No-Nonsense License Statement that
  614.   you received with the Borland product to which this information
  615.   pertains.
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.